<template>
    <checkbox-group @change="checkboxGroup($event,itmeList)">
        <span class="heckbox_s" v-for="(ite, index) in checked" :key="index">
            <label>
                <checkbox
                    class="pink"
                    :disabled="disabled"
                    :value="ite.name"
                    :checked="ite.checked"
                    color="#F75193"
                >{{ite.name}}</checkbox>
            </label>
        </span>
    </checkbox-group>
</template>
<script>
export default {
    props: {
        disabled: {
            type: Boolean,
            default: false
        },
        itmeList: {
            type: Object,
            default: {}
        },
        from: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {
            checked: []
        };
    },
    mounted() {
        var _this=this
        var array = _this.itmeList.valueList;
        var fieldName = _this.from[_this.itmeList.fieldName];
        for (var i = 0, lenI = array.length; i < lenI; ++i) {
            var itmes = array[i];
            if (fieldName&&_this.isStr(fieldName, itmes)) {
                _this.checked.push({
                    name: itmes,
                    checked: true
                });
            } else {
                _this.checked.push({
                    name: itmes,
                    checked: false
                });
            }
        }
        
    },
    methods: {
        isStr(str, val) {
            if (str.indexOf(val) != -1) {
                return true;
            } else {
                return false;
            }
        },
        checkboxGroup(e, itm) {
            this.$emit("checkboxGroup", e, itm);
        }
    }
};
</script>
